-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(serialport): add mutex for thread-safe access of isClosing
bool status
#1009
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1009 +/- ##
==========================================
- Coverage 20.14% 20.09% -0.05%
==========================================
Files 42 42
Lines 3221 3229 +8
==========================================
Hits 649 649
- Misses 2487 2495 +8
Partials 85 85
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
isClosing
bool status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only need to synchronize access to a single variable maybe an atomic.Bool
could be better?
p.mu.Lock() | ||
//if we detect that port is closing, break out of this for{} loop. | ||
if p.isClosing { | ||
strmsg := "Shutting down reader on " + p.portConf.Name | ||
log.Println(strmsg) | ||
h.broadcastSys <- []byte(strmsg) | ||
break | ||
} | ||
p.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the break
path is taken doesn't the mutex remain locked?
Please check if the PR fulfills these requirements
before creating one)
Fix a DATA RACE on the
isClosing
variable of the seiral port.There are two routines that read and write the
isClosing
variable concurrently.open
command reads theisClosing
variable to verify if it must stop reading from the serial portclose
command writes theisClosing
(setting to true) variable to inform that the serial port must be closed.Add a mutex to control the access of the shared variable (another approach could have been adding a channel to inform to close the serial port)